package com.hindua.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.hindua.beans.Item;
import com.hindua.ailaaicuaai.R;

public class ItemAdapter extends BaseAdapter {
	private ArrayList<Item> items;
	private LayoutInflater layoutInflater;
	
	public ItemAdapter(Context c, ArrayList<Item> items) {
		this.layoutInflater = LayoutInflater.from(c);
		this.items = items;
	}
	
	@Override
	public int getCount() {
		return (this.items == null) ? 0: this.items.size();
	}

	@Override
	public Object getItem(int position) {
		return this.items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = layoutInflater.inflate(R.layout.item_list, parent, false);
		}
		TextView tv = (TextView) convertView.findViewById(R.id.text_view);
		Item tmp = (Item) this.items.get(position);
		tv.setText(tmp.getName());
		return convertView;
	}
}
